home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / redo / redoSetRootEntry.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  11.5 KB  |  477 lines

  1. /*
  2.  *   $RCSfile: redoSetRootEntry.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:57 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "pool.h"
  46. #include "tid.h"
  47. #include "io.h"
  48. #include "lock.h"
  49. #include "object.h"
  50. #include "msgdefs.h"
  51. #include "thread.h"
  52. #include "latch.h"
  53. #include "semaphore.h"
  54. #include "link.h"
  55. #include "lsn.h"
  56. #include "bf.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "logrecs.h"
  60. #include "trans.h"
  61. #include "openlog.h"
  62. #include "io_extfuncs.h"
  63. #include "bf_extfuncs.h"
  64. #include "util_funcs.h"
  65. #include "trans_extfuncs.h"
  66. #include "redo_extfuncs.h"
  67. #include "redo_intfuncs.h"
  68. #include "thread_globals.h"
  69. #include "log_globals.h"
  70. #include "log_extfuncs.h"
  71.  
  72.  
  73.  void
  74. redoSetRootEntry (
  75.  
  76.     LOGRECORDHDR            *record 
  77. )
  78. {
  79.  
  80.     register ROOTENTRY        *current;
  81.     register ROOTENTRY        *end;
  82.     register VOLREC            *volRec;
  83.     register GROUPLINK        *rootLink;
  84.     register DIRTYPAGEINFO    *dirtyInfo;
  85.     char                    *newData;
  86.     FOUR                    newDataSize;
  87.     ROOTPAGE                *rootPage;
  88.     PID                        pid;
  89.     VOLID                    volid;
  90.     ROOTENTRYLOGINFO        *entryInfo;
  91.  
  92.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_1, ("lsn:%d", record->recordLSN));
  93.  
  94.     /*
  95.      *    get a pointer to the name in the record
  96.      */
  97.     volid = record->actionPid.volid;
  98.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("volid:%d", volid));
  99.  
  100.     /*
  101.      *    construct the pid
  102.      */
  103.     pid.volid = volid;
  104.     pid.page = ROOTPAGEADDR;
  105.     SM_ASSERT(LEVEL_3, ROOTPAGEADDR == record->actionPid.page);
  106.  
  107.     /*
  108.      *    check to see if the page is in the dirty page list
  109.      */
  110.     if ((dirtyInfo = searchDirtyPageTable(&pid)) == NULL)    {
  111.  
  112.         /*
  113.          *    don't need to redo
  114.          */
  115.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty page not present"));
  116.         return;
  117.     }
  118.  
  119.     /*
  120.      *  check to see if the lrc on the page is greater than
  121.      *  the lrc in the log record.
  122.      *  Also check the lsn for the case of pages which never made it
  123.      *  back from the client.
  124.      */
  125.     if (CHECK_PAGE_LRC_LESS_DIRTYINFO(record->actionLRC, record->recordLSN, dirtyInfo)) {
  126.  
  127.         /*
  128.          *  don't need to redo
  129.          */
  130.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty info page lrc later"));
  131.         return;
  132.     }
  133.  
  134.     /* get a pointer to information about the entry */
  135.     entryInfo = (ROOTENTRYLOGINFO*) GET_LOG_IMAGE(record, 0);
  136.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("name:%s", entryInfo->name));
  137.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("oldFlags:%d", entryInfo->oldFlags));
  138.  
  139.     /*
  140.      *    get a pointer to the new data and size in the record
  141.      */
  142.     newData = GET_LOG_IMAGE(record, 2);
  143.     newDataSize = GET_LOG_IMAGE_SIZE(record, 2);
  144.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("new data:%s", newData));
  145.  
  146.     if ((volRec = io_FindVolRec(volid)) == NULL) {
  147.         SM_ERROR(TYPE_FATAL, Active->errno);
  148.     }
  149.  
  150.     /*
  151.      *    read in the root page
  152.      */
  153.     if ((rootLink = bf_ReadPage(volRec->bufGroup, &pid, MIN_PAGE2SIZE, BF_SEM)) == NULL) {
  154.  
  155.         SM_ERROR(TYPE_FATAL, Active->errno);
  156.     }
  157.  
  158.     /*
  159.      *    get a pointer to the root page
  160.      */
  161.     rootPage = (ROOTPAGE *) rootLink->bufFrame;
  162.  
  163.     /*
  164.      *    check to see if the lrc on the page is greater than
  165.      *    the lrc in the log record
  166.      */
  167.     if (compareLRC( &(record->actionLRC), &(rootPage->lrc)) <= 0) {
  168.  
  169.         /*
  170.          *    don't need to redo
  171.          *    mark the page lsn
  172.          */
  173.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("actual page lrc later"));
  174.         dirtyInfo->lrc = rootPage->lrc;
  175.  
  176.         /*
  177.          *    release the page
  178.          */
  179.         signalSemaphore( &(rootLink->pageHash->semaphore) );
  180.         bf_UnfixPage(rootLink, BF_DEFAULT, FALSE);
  181.         return;
  182.     }
  183.  
  184.     /*
  185.      *    Initialize the search variables
  186.      */
  187.     current = &(rootPage->entry[0]);
  188.     end = &(rootPage->entry[MAX_ROOT_ENTRIES]);
  189.  
  190.     /*
  191.      *    See if the root entry was originally allocated in a free
  192.      *    entry slot.
  193.      */
  194.     if (entryInfo->oldFlags == ROOT_FREE) {
  195.  
  196.         /*
  197.          *    look for a free spot
  198.          */
  199.         while (current < end)    {
  200.  
  201.             /*
  202.              *    check to see if the slot is free
  203.              */
  204.             if (current->flags == ROOT_FREE)    {
  205.  
  206.                 /*
  207.                  *    free the information
  208.                  */
  209.                 current->flags = ROOT_USED;
  210.  
  211.                 /*
  212.                  *    plug in the information
  213.                  */
  214.                 strncpy(current->name, (char *)entryInfo->name, MAX_ROOTNAME_SIZE);        
  215.                 bcopy(newData, current->data, (int)newDataSize);
  216.                 current->dataSize = newDataSize;
  217.  
  218.                 /*
  219.                  *    mark the lsn
  220.                  *    Set up the firstLSN/LRC for the page
  221.                  */
  222.                 rootPage->lrc = record->actionLRC;
  223.                 DEPEND_LOG(rootLink->pageHash, 0, &(record->recordLSN), &(record->actionLRC));
  224.                 TRPRINT(TR_RECOVER, TR_LEVEL_2, ("marking new page lrc:%d",
  225.                         rootPage->lrc.count));
  226.  
  227.                 /* 
  228.                  *    signal the semaphore and unfix the page
  229.                  */
  230.                 signalSemaphore( &(rootLink->pageHash->semaphore) );
  231.                 bf_UnfixPage(rootLink, BF_DEFAULT, TRUE);
  232.         
  233.                 return;
  234.             }
  235.  
  236.             /*
  237.              *    look at the next entry
  238.              */
  239.             current++;
  240.         }
  241.  
  242.         /*
  243.          *    There should be a free entry since history is being
  244.          *    redone.  So, return an error.
  245.          */
  246.         TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("no match"));
  247.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  248.  
  249.     } else { 
  250.         
  251.         /* 
  252.          *    This entry already existed, but the set operation
  253.          *    changed the data, so search for the entry and
  254.          *    change the data.
  255.          */
  256.         while (current < end)   {
  257.  
  258.             /*
  259.              *  check to see if the slot is free
  260.              */
  261.             if (current->flags != ROOT_FREE)    {
  262.  
  263.                 /*
  264.                  *  check to see if the name matches
  265.                  */
  266.                 if (!strcmp(current->name, (char *)entryInfo->name))   {
  267.  
  268.                     TRPRINT(TR_IO, TR_LEVEL_2, ("found name at slot:%d", current->index));
  269.                     /*
  270.                      *  plug in the information
  271.                      */
  272.                     bcopy(newData, current->data, (int)newDataSize);
  273.                     current->dataSize = newDataSize;
  274.  
  275.                     /*
  276.                      *    mark the lsn
  277.                      *    Set up the firstLSN/LRC for the page
  278.                      */
  279.                     rootPage->lrc = record->actionLRC;
  280.                     DEPEND_LOG(rootLink->pageHash, 0, &(record->recordLSN), &(record->actionLRC));
  281.                     TRPRINT(TR_RECOVER, TR_LEVEL_2, ("marking new page lrc:%d",
  282.                             rootPage->lrc.count));
  283.  
  284.                     /* 
  285.                      *    signal the semaphore, unfix the page and return
  286.                      */
  287.                     signalSemaphore( &(rootLink->pageHash->semaphore) );
  288.                     bf_UnfixPage(rootLink, BF_DEFAULT, TRUE);
  289.                     return;
  290.                 }
  291.             }
  292.             
  293.             /*
  294.              *    look at the next entry
  295.              */
  296.             current++;
  297.         }
  298.  
  299.         /*
  300.          *    There should be a matching entry since history is being
  301.          *    redone.  So, return an error.
  302.          */
  303.         TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("name not found"));
  304.         SM_ERROR(TYPE_FATAL, esmBADROOTNAME);
  305.  
  306.     }
  307.  
  308.     /*
  309.      *    This statement should not be reached
  310.      */
  311.     SM_ERROR(TYPE_FATAL, esmINTERNAL);
  312. }
  313.  
  314.  
  315.  
  316.  
  317.  void
  318. redoRemoveRootEntry (
  319.  
  320.     LOGRECORDHDR            *record 
  321. )
  322. {
  323.  
  324.     ROOTENTRY            *current;
  325.     ROOTENTRY            *end;
  326.     VOLREC                *volRec;
  327.     GROUPLINK            *rootLink;
  328.     DIRTYPAGEINFO        *dirtyInfo;
  329.     ROOTPAGE            *rootPage;
  330.     PID                    pid;
  331.     VOLID                volid;
  332.     ROOTENTRYLOGINFO    *entryInfo;
  333.  
  334.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_1, ("lsn:%d", record->recordLSN));
  335.  
  336.     /* get a pointer to the name in the record */
  337.     volid = record->actionPid.volid;
  338.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("volid:%d", volid));
  339.  
  340.     /* construct the pid */
  341.     pid.volid = volid;
  342.     pid.page = ROOTPAGEADDR;
  343.     SM_ASSERT(LEVEL_3, ROOTPAGEADDR == record->actionPid.page);
  344.  
  345.     /* check to see if the page is in the dirty page list */
  346.     if ((dirtyInfo = searchDirtyPageTable(&pid)) == NULL)    {
  347.  
  348.         /* don't need to redo */
  349.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty page not present"));
  350.         return;
  351.     }
  352.  
  353.     /*
  354.      *  check to see if the lrc on the page is greater than
  355.      *  the lrc in the log record.
  356.      *  Also check the lsn for the case of pages which never made it
  357.      *  back from the client.
  358.      */
  359.     if ( (compareLRC(&(record->actionLRC), &(dirtyInfo->lrc)) < 0) ||
  360.          (compareLSN(&(record->recordLSN), &(dirtyInfo->lsn)) < 0) ) {
  361.  
  362.         /* don't need to redo */
  363.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty info page lrc later"));
  364.         return;
  365.     }
  366.  
  367.     /*
  368.      *  Make sure the comparison was correct
  369.      */
  370.     SM_ASSERT(LEVEL_3, compareLSN( &(record->recordLSN), &(dirtyInfo->lsn)) >= 0);
  371.  
  372.     /* get a pointer to information about the entry */
  373.     entryInfo = (ROOTENTRYLOGINFO*) GET_LOG_IMAGE(record, 0);
  374.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("name:%s", entryInfo->name));
  375.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("oldFlags:%d", entryInfo->oldFlags));
  376.  
  377.     if ((volRec = io_FindVolRec(volid)) == NULL) {
  378.         SM_ERROR(TYPE_FATAL, Active->errno);
  379.     }
  380.  
  381.     /*
  382.      *    read in the root page
  383.      */
  384.     if ((rootLink = bf_ReadPage(volRec->bufGroup, &pid, MIN_PAGE2SIZE, BF_SEM)) == NULL) {
  385.  
  386.         SM_ERROR(TYPE_FATAL, Active->errno);
  387.     }
  388.  
  389.     /*
  390.      *    get a pointer to the root page
  391.      */
  392.     rootPage = (ROOTPAGE *) rootLink->bufFrame;
  393.  
  394.     /*
  395.      *    check to see if the lrc on the page is greater than
  396.      *    the lrc in the log record
  397.      */
  398.     if (compareLRC( &(record->actionLRC), &(rootPage->lrc)) <= 0) {
  399.  
  400.         /*
  401.          *    don't need to redo
  402.          *    mark the page lsn
  403.          */
  404.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("actual page lrc later"));
  405.         dirtyInfo->lrc = rootPage->lrc;
  406.  
  407.         /* release the page */
  408.         signalSemaphore( &(rootLink->pageHash->semaphore) );
  409.         bf_UnfixPage(rootLink, BF_DEFAULT, FALSE);
  410.         return;
  411.     }
  412.  
  413.     /*
  414.      *    Initialize the search variables
  415.      */
  416.     current = &(rootPage->entry[0]);
  417.     end = &(rootPage->entry[MAX_ROOT_ENTRIES]);
  418.  
  419.     /* 
  420.      *    This entry already existed, but the set operation
  421.      *    changed the data, so search for the entry and
  422.      *    change the data.
  423.      */
  424.     while (current < end)   {
  425.  
  426.         /*
  427.          *  check to see if the slot is free
  428.          */
  429.         if (current->flags != ROOT_FREE)    {
  430.  
  431.             /*
  432.              *  check to see if the name matches
  433.              */
  434.             if (!strcmp(current->name, (char *)entryInfo->name))   {
  435.  
  436.                 TRPRINT(TR_IO, TR_LEVEL_2, ("found name at slot:%d", current->index));
  437.             
  438.                 /* mark the entry free */
  439.                 current->flags = ROOT_FREE;
  440.  
  441.                 /*
  442.                  *    mark the lsn
  443.                  *    Set up the firstLSN/LRC for the page
  444.                  */
  445.                 rootPage->lrc = record->actionLRC;
  446.                 DEPEND_LOG(rootLink->pageHash, 0, &(record->recordLSN), &(record->actionLRC));
  447.                 TRPRINT(TR_RECOVER, TR_LEVEL_2, ("marking new page lrc:%d",
  448.                         rootPage->lrc.count));
  449.  
  450.                 /* 
  451.                  *    signal the semaphore, unfix the page and return
  452.                  */
  453.                 signalSemaphore( &(rootLink->pageHash->semaphore) );
  454.                 bf_UnfixPage(rootLink, BF_DEFAULT, TRUE);
  455.                 return;
  456.             }
  457.         }
  458.         
  459.         /*
  460.          *    look at the next entry
  461.          */
  462.         current++;
  463.     }
  464.  
  465.     /*
  466.      *    There should be a matching entry since history is being
  467.      *    redone.  So, return an error.
  468.      */
  469.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("name not found"));
  470.     SM_ERROR(TYPE_FATAL, esmBADROOTNAME);
  471.  
  472.     /*
  473.      *    This statement should not be reached
  474.      */
  475.     SM_ERROR(TYPE_FATAL, esmINTERNAL);
  476. }
  477.